package org.pupil.filter;

import org.pupil.filter.client.ClientAfterFilter;
import org.pupil.filter.client.ClientBeforeFilter;
import org.pupil.filter.server.ServerAfterFilter;
import org.pupil.filter.server.ServerBeforeFilter;
import org.pupil.spi.ExtensionLoader;

import java.io.IOException;
import java.util.List;

/**
 * @Description: 拦截器工厂，责任链模式
 * @Author: pupil
 * @Date: 2024/07/17 下午 5:55
 */
public class FilterFactory {

    // 初始化服务发送方拦截器链
    public static void initClient() throws IOException, ClassNotFoundException {
        ExtensionLoader.getInstance().loadExtension(ClientBeforeFilter.class);
        ExtensionLoader.getInstance().loadExtension(ClientAfterFilter.class);
    }

    // 初始化服务提供方拦截器链
    public static void initServer() throws IOException, ClassNotFoundException {
        ExtensionLoader.getInstance().loadExtension(ServerBeforeFilter.class);
        ExtensionLoader.getInstance().loadExtension(ServerAfterFilter.class);
    }

    // 获取服务发送方前置拦截器链
    public static List<Filter> getClientBeforeFilters() {
        return ExtensionLoader.getInstance().gets(ClientBeforeFilter.class);
    }

    // 获取服务发送方后置拦截器链
    public static List<Filter> getClientAfterFilters() {
        return ExtensionLoader.getInstance().gets(ClientAfterFilter.class);
    }

    // 获取服务提供方前置拦截器链
    public static List<Filter> getServerBeforeFilters() {
        return ExtensionLoader.getInstance().gets(ServerBeforeFilter.class);
    }

    // 获取服务提供方后置拦截器链
    public static List<Filter> getServerAfterFilters() {
        return ExtensionLoader.getInstance().gets(ServerAfterFilter.class);
    }
}
